package com.zy.design.pattern.di;

import com.zy.design.pattern.di.entity.RateLimiter;
import com.zy.design.pattern.di.entity.RedisCounter;

import java.io.InputStream;

/**
 * @author zhaoyi
 * @date 2021/3/30 16:08
 * DI容器的核心功能一般有三个：
 * 配置解析
 * 对象创建
 * 对象生命周期管理
 *
 *  工厂模式 BeanFactory
 *
 *
 *  利用建造者模式场景 ConstructorArgs
 *      1 类的构造函数必填属性很多
 *      2 如果类的属性之间有一定的依赖关系校验
 *
 */
public class DITs {
    public static void main(String[] args) {

        System.out.println("========================================");

        RedisCounter redisCounter = (RedisCounter) BeanFactory.getBean("redisCounter");
        RedisCounter redisCounter2 = (RedisCounter) BeanFactory.getBean("redisCounter");
        System.out.println(redisCounter);
        System.out.println(redisCounter2);
        System.out.println(redisCounter2 == redisCounter);

        RateLimiter rateLimiter = (RateLimiter) BeanFactory.getBean("rateLimiter");
        RateLimiter rateLimiter2 = (RateLimiter) BeanFactory.getBean("rateLimiter");
        System.out.println(rateLimiter);
        System.out.println(rateLimiter == rateLimiter2);

        RateLimiter rs1 = (RateLimiter) BeanFactory.getBean("rateLimiter-singleton");
        RateLimiter rs2 = (RateLimiter) BeanFactory.getBean("rateLimiter-singleton");
        System.out.println(rs1);
        System.out.println(rs1 == rs2);






    }
}
